package models

import (
	"time"
)

type User struct {
	Id   int
	Uuid string `orm:"unique;index;size(32)"` //唯一uuid
	Nick string `orm:"size(128)"`             //昵称
	Himg string `orm:"size(256)"`             //头像地址

	Enable  bool `orm:"default(1)"`
	Deleted bool `orm:"default(0)"`

	CreateAt time.Time `orm:"auto_now_add;type(datetime)"` //创建时设置为当前时间
	UpdateAt time.Time `orm:"auto_now;type(datetime)"`     //创建更新设置为当前时间

	//	Roles     []*Role     `orm:"rel(m2m)"`
	//	Auths     []*Auth     `orm:"reverse(many)"`
	//	Resources []*Resource `orm:"reverse(many)"`
	//	Binders   []*Binder   `orm:"reverse(many)"`
	//	Comments  []*Comment  `orm:"reverse(many)"`
	//	Upvotes   []*Upvote   `orm:"reverse(many)"`
	//	Downloads []*Download `orm:"reverse(many)"`

	//	ScoreAmount *ScoreAmount `orm:"reverse(one)"`
	//	ScoreTails  []*ScoreTail `orm:"reverse(many)"`
}

type Auth struct {
	Id     int
	Flag   int
	OpenId string `orm:"size(64)"`
	Passwd string `orm:"size(64)"`
	Email  string `orm:"size(128)"`
	Ext    string `orm:"size(4096)"`

	CreateAt time.Time `orm:"auto_now_add;type(datetime)"` //创建时设置为当前时间
	UpdateAt time.Time `orm:"auto_now;type(datetime)"`     //创建更新设置为当前时间

	UserId string `orm:"size(32)"`
}

func (p *Auth) TableUnique() [][]string {
	return [][]string{
		[]string{"Flag", "OpenId"},
	}
}

func (p *Auth) TableIndex() [][]string {
	return [][]string{
		[]string{"Flag", "OpenId"},
	}
}

type Role struct {
	Id int

	Plivilege int `orm:"unique;index;`

	Version  int64     //每次更新时自动+1
	CreateAt time.Time `orm:"auto_now_add;type(datetime)"` //创建时设置为当前时间
	UpdateAt time.Time `orm:"auto_now;type(datetime)"`     //创建更新设置为当前时间
}

type UserRoles struct {
	Id int

	UserId string `orm:"size(64); index"`
	RoleId int
}

func (p *UserRoles) TableUnique() [][]string {
	return [][]string{
		[]string{"UserId", "RoleId"},
	}
}
